﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Personalization.VisitorGroups;
using System.ComponentModel.DataAnnotations;
using EPiServer.XForms;
using EPiServer.Web.Mvc.VisitorGroups;

namespace CriteriaPack.XFormsCriterion
{
    public class XFormModel:CriterionModelBase
    {

        //Check for Form submitted / not submitted, Form value exist, Form value contains, Form value equals

        [Required]
        [DojoWidget(SelectionFactoryType = typeof(EnumSelectionFactory), LabelTranslationKey = "/shell/cms/visitorgroups/criteria/xform/submissionstatus", AdditionalOptions = "{ selectOnClick: true }")]
        public SubmissionStatus SubmissionStatus { get; set; }

        [Required]
        [DojoWidget(SelectionFactoryType = typeof(FormSelectionFactory), LabelTranslationKey = "/shell/cms/visitorgroups/criteria/xform/selectedxform", AdditionalOptions = "{ selectOnClick: true }")]
        public string SelectedXForm { get; set; }

        public override ICriterionModel Copy()
        {
            return base.ShallowCopy();
        }
    }

    public class FormSelectionFactory : ISelectionFactory
    {
        #region ISelectionFactory Members

        public IEnumerable<System.Web.Mvc.SelectListItem> GetSelectListItems(Type property)
        {
            //Return list of forms
            return XForm.GetForms().Select(xf => new System.Web.Mvc.SelectListItem() { Text=xf.FormName, Value=xf.Id.ToString() });
        }

        #endregion
    }

    public enum SubmissionStatus
    {
        HasSubmitted,
        HasNotSubmitted
    }
}
